#!/bin/bash

if [ "$(id -u)" -ne 0 ]; then
  echo "This script should run as root."
  exit 1
fi

cpufreq-set -g performance
# 使用如下命令查看CPU所属模式
# cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
# 查看CPU状态
# cpufreq-info

# 通过以下命令设置CPU亲和性（使核3空闲，不处理中断）
for irq in $(cat /proc/interrupts | awk '{print $1}' | tr -d ':'); do
    echo 7 > /proc/irq/$irq/smp_affinity
done

# 不重启电脑，禁用swap，立刻生效
swapoff -a

# 你要启动的程序路径或命令
command="./como_fscp_voter"

# 无限循环，确保进程退出后重启
while true; do
    # 启动进程
    echo "Starting process: $command"
    $command

    # 检查进程是否退出
    if [ $? -ne 0 ]; then
        echo "Process $command exited with status $?. Restarting..."
    else
        echo "Process $command exited normally."
        exit 2
    fi

    # 可以在这里添加延迟（可选）
    # sleep 1
done
